/*
 * Created on Jun 5, 2004
 */
package dk.aiszone.lang.autosource.generatorobjects;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * Representation of the contents of an interface.<br>
 * This object contains the <code>MethodsDeclarations</code> of the interface.
 * 
 * @author <a href="mailto:ais@mail.dk">Ais</a>
 * @since 1.0
 * @version 1.0
 */
public class InterfaceBody extends AbstractBody<MethodDeclaration> {

    /**
     * Default constructor of the <code>InterfaceBody</code>.<br>
     * Using the constructor requires the <code>declaration</code> and <code>name</code> to be set later.
     * 
     * @see #setDeclaration(Declaration)
     * @see #setName(String)
     */
    public InterfaceBody() {
        super();
    }

    /**
     * Constructor of the <code>InterfaceBody</code>.
     * 
     * @param declaration
     *            The <code>Declaration</code> of the body.
     * @param name
     *            The name of the body.
     */
    public InterfaceBody(Declaration declaration, String name) {
        super(declaration, name);
    }

    /**
     * Adds a <code>Class</code> to the <code>List</code> of classes extended by this interface.
     * 
     * @param _extends
     *            <code>Class</code> being extended.
     */
    public void addExtends(Class _extends) {
        extendsClasses.add(_extends);
    }

    /**
     * Retrieve the <code>List</code> of <code>Classes</code> being extended by the <code>InterfaceBody</code>
     * 
     * @return Unmodifiable <code>List</code> of extended <code>Classes</code>
     */
    public List<Class> getExtends() {
        return Collections.unmodifiableList(extendsClasses);
    }

    /**
     * Retrieve all the <code>MethodDeclarations</code> of the <code>InterfaceBody</code>.
     * 
     * @return <code>List</code> of declared <code>MethodDeclarations</code>.
     */
    public List<MethodDeclaration> getMethodDeclarations() {
        List<MethodDeclaration> methodsList = new ArrayList<MethodDeclaration>();
        for (Iterator<Set<MethodDeclaration>> iter = methods.values().iterator(); iter.hasNext();) {
            Set<MethodDeclaration> set = iter.next();
            methodsList.addAll(set);
        }

        return methodsList;
    }

    @Override protected Object clone() throws CloneNotSupportedException {
        InterfaceBody clone = new InterfaceBody();

        cloneDefaultAttributes(clone);

        return clone;
    }
}